/**
 * @PROJECT 
 * @DATE 2018年7月12日 上午10:15:35
 * @AUTHOR LUYU
 */
package com.kool.system.action.roleGroup;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kool.core.base.IBaseAction;
import com.kool.core.exception.AppException;
import com.kool.core.util.BeanUtils;
import com.kool.system.bean.SyRoleGroupAutBean;
import com.kool.system.bean.io.roleGroup.SYAUTGROUPXBean;
import com.kool.system.service.RoleGroupService;

/**
 * @DESCRIBE
 * @AUTHOR LUYU
 * @DATE 2018年7月12日 上午10:15:35
 *
 */
@Controller
public class AuthGroupAction implements IBaseAction {
	@Autowired
	private RoleGroupService service;

	@Override
	@ResponseBody
	@RequestMapping(value = "/sys/roleGroup/resetAut", method = RequestMethod.POST)
	public JSONObject doAction(@RequestBody String sInput) throws AppException {
		JSONObject pkgIn = JSONObject.parseObject(sInput);
		JSONArray secGroup = pkgIn.getJSONArray("SYGROUPCODEX");
		JSONObject propGroup = secGroup.getJSONObject(0);
		String groupCode = propGroup.getString("groupCode");

		JSONArray secAut = pkgIn.getJSONArray("SYAUTGROUPX");
		List<SyRoleGroupAutBean> listIn = new ArrayList<>();
		for (int i = 0; i < secAut.size(); i++) {
			SYAUTGROUPXBean io = JSON.toJavaObject(secAut.getJSONObject(i), SYAUTGROUPXBean.class);
			SyRoleGroupAutBean roleAut = (SyRoleGroupAutBean) BeanUtils.io2Bean(io, SyRoleGroupAutBean.class, "sga");
			listIn.add(roleAut);
		}
		service.resetAuth(groupCode, listIn);

		return null;
	}

}
